/************************************************************************/
/*
	pengl add
*/
/************************************************************************/
#pragma once

#include "common.h"


/************************************************************************/
/* 
	callback function
*/
/************************************************************************/
typedef BOOL (*set_audioFomatDlgPtr(void *ptr));


/************************************************************************/
/* main video setting defined here                                                                     */
/************************************************************************/
#define		CONFIG_VideoEnc		"VideoEnc"
#define		CONIFG_VideoBR		"VideoBR"
#define		CONFIG_VideoSize	"VideoSize"
#define		CONFIG_Videofps		"Videofps"
#define		CONFIG_VideoMthread "VideoMthread"
#define		CONFIG_ScaleUpTo	"ScaleUpTo"
#define		CONFIG_Xcmd			"Xcmd"
#define		CONFIG_Xvc			"Xvc"
#define		CONFIG_Xvfpre		"Xvfpre"
#define		CONFIG_Xvf			"Xvf"

/************************************************************************/
/* 
	audio
*/
/************************************************************************/
#define		CONFIG_AudioEnc		"AudioEnc"
#define		CONFIG_AudioHz		"AudioHz"
#define		CONFIG_AudioBR		"AudioBR"
#define		CONFIG_AACMpeg		"AACMpeg"
#define		CONFIG_AACObject	"AACObject"
#define		CONFIT_AudioStream  "AudioStream"
#define		CONFIG_AudioChannel "AudioChannel"

#define		CONFIG_Xac			"Xac"
#define		CONFIG_Xaf			"Xaf"
#define		CONFIG_Xss			"Xss"
#define		CONFIG_Xendpos		"Xendpos"
#define		CONFIG_Xof			"Xof"

/************************************************************************/
/* Misc audio defined here                                                                     */
/************************************************************************/
#define		CONFIG_AudioQuality	"AudioQuality"
#define		CONFIG_MP3Mode		"MP3Mode"
#define		CONFIG_AudioID		"AudioID"
#define		CONFIG_MP3Vol		"MP3Vol"
#define		CONFIG_MP3Encode	"MP3Encode"
#define		CONFIG_MP3AQ		"MP3AQ"
#define		CONFIG_VolNorm		"VolNorm"

/************************************************************************/
/* Misc video */
/************************************************************************/

#define		CONFIG_VHQ			"VHQ"
#define		CONFIG_2pass		"2pass"
#define		CONFIG_1PassTurbo	"1PassTurbo"
#define		CONFIG_Deinterlace	"Deinterlace"
#define		CONFIG_Ivtc			"Ivtc"
#define		CONFIG_ScaleUpTo	"ScaleUpTo"
#define		CONFIG_vqscale		"vqscale"
#define		CONFIG_fixed_quant	"fixed_quant"
#define		CONFIG_crf			"crf"
#define		CONFIG_Aspect		"Aspect"
#define		CONFIG_VideoQuality	"VideoQuality"





/************************************************************************/
/* 
	const values for Output file format defined here
*/
/************************************************************************/
#define		CONFIG_OF_AVI		"AVI"
#define		CONFIG_OF_MP4		"MP4"
#define		CONFIG_OF_MPEG		"MPEG video"
#define		CONFIG_OF_MPEG_PS	"MPEG-PS"
#define		CONFIG_OF_MPEG_TS	"MPEG-TS"
#define		CONFIG_OF_OGM		"OGM"
#define		CONFIG_OF_FLV		"FLV"
#define		CONFIG_OF_MKV		"MKV"




/************************************************************************/
/* 
	NULL macro
*/
/************************************************************************/
#define IN
#define OUT

/************************************************************************/
/* 
	callback functions
*/
/************************************************************************/
typedef void (*cb_Notify_setting_param(const char *szType, const char *strVal, const int intVal));




/************************************************************************/
/*
	struct defined here
*/
/************************************************************************/
typedef struct s_FormatVideoCodec {
	char fmt_v_codec[16];		//video codec name
	/************************************************************************/
	/*
		selected only one of settings
	*/
	/************************************************************************/
	char fmt_v_bitrate[16];		//bitrate
	int	 fmt_v_quality;			//video qulity (crf)
	
	/************************************************************************/
	/* 
		const values
	*/
	/************************************************************************/
	char fmt_v_vsize[16];		//video solution
	char fmt_v_fr[16];			//framerate
	char fmt_v_uptoscale[16];	//scale
	char fmt_v_aspect[16];		//pic aspect except for x264s
	char fmt_v_pixelAspect[16];	//pixel aspect for x264
	char fmt_v_thread[16];		//thread
	
	/************************************************************************/
	/* 
		check box values
	*/
	/************************************************************************/
	BOOL fmt_v_hqv;				//high quality for Divx
	BOOL fmt_v_2pass;			//2pass 
	BOOL fmt_v_1passTurbo;		//1pass turbo
	BOOL fmt_v_deinterlace;		//deinterlace
	BOOL fmt_v_ivtc;			//inverse telecine
	BOOL fmt_v_fit2width;		//fit to width
	BOOL fmt_v_fit2height;		//fit to height
	BOOL fmt_v_expand_vs;		//expand to video size
	BOOL fmt_v_round_16pixel;	//round to 16 pixel

	/************************************************************************/
	/* 
		video extra configure defined here	
	*/
	/************************************************************************/
	char fmt_v_Xvf[256];		//video filter
	char fmt_v_Xvc[256];		//video codec setting	
	char fmt_v_Xcmd[256];		
}s_FormatVideoCodec, *Ps_FormatVideoCodec;


typedef enum em_AUDIO_FILTER{
	LEFT_STEREO,
	RIGHT_STEREO,
	LEFT_MONO,
	RIGHT_MONO,
	MIXED_MONO
}em_AUDIO_FILTER;

/************************************************************************/
/* 
	mp3 defined here
*/
/************************************************************************/
typedef struct s_FormatAudioCodec_MP3 {
	int fmt_sample;
	int	fmt_bitrate;
	char fmt_mp3encode[16];
	char fmt_mp3mode[16];
	char fmt_mp3volume[16];
	char fmt_mp3AQ[16];
	int	fmt_astream;
	int fmt_afilter;  //em_AUDIO_FILTER
}s_FormatAudioCodec_MP3, *Ps_FormatAudioCodec_MP3;

/************************************************************************/
/* 
	aac defined here
*/
/************************************************************************/
typedef struct s_FormatAudioCodec_AAC {
	int fmt_sample;
	int fmt_bitrate;
	int fmt_mpegtype;
	int fmt_objectype;
	int fmt_astream;
	int fmt_afilter; //em_AUDIO_FILTER
}s_FormatAudioCodec_AAC, *Ps_FormatAudioCodec_AAC;

/************************************************************************/
/* 
	ac3 defined here
*/
/************************************************************************/
typedef struct s_FormatAudioCodec_AC3 {
	int fmt_sample;
	int fmt_bitrate;
	int fmt_astream;
	int fmt_afilter;
}s_FormatAudioCodec_AC3, *Ps_FormatAudioCodec_AC3;

/************************************************************************/
/* 
	mp2 defined here
*/
/************************************************************************/
typedef struct s_FormatAudioCodec_MP2 {
	int fmt_sample;
	int fmt_bitrate;
	int fmt_astream;
	int fmt_afilter;
}s_FormatAudioCodec_MP2, *Ps_FormatAudioCodec_MP2;


/************************************************************************/
/* 
	audio codec wrapper struct
*/
/************************************************************************/
typedef struct s_FormatAudioCodec {
	char fmt_acodec_name[16];
	char fmt_acodec_Xaf[256];
	s_FormatAudioCodec_MP3 s_mp3;
	s_FormatAudioCodec_AAC s_aac;
	s_FormatAudioCodec_AC3 s_ac3;
	s_FormatAudioCodec_MP2 s_mp2;
}s_FormatAudioCodec, *Ps_FormatAudioCodec;

typedef void (*CB_showProgress)(int state, float time);

enum PROGRESS_STATE {
	STATE_CONVERT,
	STATE_VCOPY,
	STATE_ACOPY,
	STATE_MP4BOX,
	STATE_PSP
};

/************************************************************************/
/* 
	codec profile wrapper class defined here
*/
/************************************************************************/
class MPLAYER_API CConfigParse
{
public:
	CConfigParse(void);
	/************************************************************************/
	/*	\profile
			-1 none profle setting will be selected
			>0 read params from current selected profles
	*/
	/************************************************************************/
	CConfigParse(IN int profile);

	CConfigParse(IN CWnd *pWnd);
	~CConfigParse(void);

	void set_prgsState(int state) {
		m_state = state;
	}
	int get_prgsState() const {
		return m_state;
	}

	void set_Combox_profile(IN CWnd *pWnd);
	int	get_cur_profile();
	CString parse_vcodec();
	CString parse_acodec();
	
	void parse_vcodec(CString &strSec, CString &strVal);
	void parse_acodec(CString &strSec, CString &strVal);

	set_audioFomatDlgPtr CB_audioFormatDlg;
	void Notify_setting_param(const char *szType, const char *strVal, const int intVal);

	void set_OutputFormat(const char *szOutFormat);
	void get_CurProfile(CString &strProfile) {
		strProfile = m_profile_name;
	}

	/************************************************************************/
	/* 
		set log output windows
	*/
	/************************************************************************/
	void void_setLog_wnd(IN CWnd *pWnd) {
		m_pLogWnd = pWnd;
	}

	/************************************************************************/
	/* 
		set progress callback functions
	*/
	/************************************************************************/
	void set_cbprogress(CB_showProgress cb) {
			ASSERT(cb != NULL);
			ShowProgress = cb;
	}
	void set_FilelistIndex(int index) {
		m_nItem = index;
	}
	int get_FilelistIndex() {
		return m_nItem;
	}

	/************************************************************************/
	/* 
		total output format
	*/
	/************************************************************************/
	CString m_strProfileXof;
	s_FormatVideoCodec m_fmtVideoCodec;
	s_FormatAudioCodec m_fmtAudioCodec;

	/************************************************************************/
	/* 
		control File list controls
	*/
	/************************************************************************/
	int m_nItem; //index of Filelist
	CB_showProgress ShowProgress;
	
	CWnd *m_pLogWnd;


protected:
	/************************************************************************/
	/* 
		progress state
	*/
	/************************************************************************/
	int m_state;

	/************************************************************************/
	/* functions                                                                     */
	/************************************************************************/
	CString get_sectiong_values(const char *sec_name);
	
	BOOL parse_aac(CString &strVal);
	BOOL parse_ac3(CString &strVal);
	BOOL parse_mp3(CString &strVal);
	BOOL parse_mp2(CString &strVal);
	BOOL parse_acopy(CString &strVal);
	BOOL parse_NoAudio(CString &strVal);
	
	CString parse_x264();
	CString parse_Divx();
	CString parse_Xvid();
	CString parse_mpeg1();
	CString parse_mpeg2();
	CString parse_vcopy();
	CString parse_NoVideo();


	/************************************************************************/
	/* members                                                                     */
	/************************************************************************/
	CString m_profile_name;
	CComboBox *m_pCmb_profile;
	int m_cur_profile;

	
	CString m_strOutFormat;

	/************************************************************************/
	/* 
		codec information
	*/
	/************************************************************************/
	s_FormatAudioCodec_MP3 m_fmtMp3;
	s_FormatAudioCodec_AAC m_fmtAAC;
	s_FormatAudioCodec_AC3 m_fmtAC3;
	s_FormatAudioCodec_MP2 m_fmtMP2;	
};
